<?php


class dbaNewsletter {

  function dbaNewsletter (&$dba){
    $this->dba = &$dba;
  }

  function addemail ($email,$rubrik){
    $this->dba->query("insert into ".$this->dba->tableforwarder."_newsletter (email,rubrik) values ('$email',$rubrik);");
  }
  
  function delemail ($email,$rubrik){
    $this->dba->query("delete from ".$this->dba->tableforwarder."_newsletter where email='$email' and rubrik = $rubrik;");
  }
  
  function checkemail ($email,$rubrik){
    if (preg_match("/^[a-zA-z0-9\-_\.]+\@[a-zA-Z0-9\-\.]+\.[a-zA-Z]+$/",$email)){
      $this->dba->query("select * from ".$this->dba->tableforwarder."_newsletter where email='$email' and rubrik = $rubrik;");
      if ($this->dba->num_rows() > 0){
        return 1;
      } else {
        return 0;
      }
    } else {
       return -1;
    }
  }
  
  function send ($rubrik,$subject,$text,$from){
    $this->dba->query("select * from ".$this->dba->tableforwarder."_newsletter where rubrik = $rubrik;");
    for ($i=0;$i<$this->dba->num_rows();$i++){
      $dset = $this->dba->fetch_row_array();
      mail($dset['email'],$subject,$text,"From: $from");
    }
  }

 function addRubrik ($name,$status){
   return $this->dba->query("insert into ".$this->dba->tableforwarder."_nlrubriken (name,status) values ('$name','$status');");
 }

 function updateRubrik ($id,$name,$status){
   return $this->dba->query("update ".$this->dba->tableforwarder."_nlrubriken set name='$name',status='$status' where id=$id;");
 }

 function updateStatusRubrik ($id,$status){
   return $this->dba->query("update ".$this->dba->tableforwarder."_nlrubriken set status'=$status') where id=$id;");
 }

 function delRubrik ($id){
   return $this->dba->query("delete from ".$this->dba->tableforwarder."_nlrubriken where id=$id;");
 }
 
 function getRubrik ($id){
   $this->dba->query("select * from ".$this->dba->tableforwarder."_nlrubriken where id=$id;");
   return $this->dba->fetch_row_array();
 }

 function getRubriken (){
   $this->dba->query("select * from ".$this->dba->tableforwarder."_nlrubriken;");
   return $this->dba->fetch_rows_array();
 }

 function getPubRubriken (){
   $this->dba->query("select * from ".$this->dba->tableforwarder."_nlrubriken where status='p';");
   return $this->dba->fetch_rows_array();
 }


}

?>
